<!--
 * @Author: tenet 18742176629@163.com
 * @Date: 2024/7/18 上午11:42
 * @LastEditors: tenet 18742176629@163.com
 * @LastEditTime: 2024/7/18 上午11:42
 * @FilePath: G:/chain-link-api-front/src/views/web3Tools/beautifulWallet\index4.vue
 * @Description: Description
-->
<template>
  <div>
    <h1>vue3-Worker</h1>
    <button @click="openWorker">开启线程</button>
    <p>F12打开浏览器控制台查看效果</p>
  </div>
</template>

<script setup>
const openWorker = () => {
  const worker = new Worker(new URL('./worker.js', import.meta.url))
  console.log('worker', import.meta.url)
  // const worker = new Worker(new URL('./worker.js', import.meta.url), {
  //   type: 'module',
  // })

  worker.postMessage('开启线程')
  worker.onmessage = e => {
    console.log(e.data)
    setTimeout(() => {
      worker.postMessage('线程关闭')
      worker.terminate()
    }, 1000)
  }
}
</script>

<style scoped lang="less">

</style>